package com.baosight.sczx.zm.cd.service;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.QueryMap;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.cd.Documents;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.common.zm.domain.ZMCDDocuments;
import com.baosight.sczx.common.zm.domain.ZMCDFiles;

/**
 * <p>Title: ServiceZMCD06.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 张志芳
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-20 下午01:24:12  张志芳  Create
 *</pre>
 */
public class ServiceZMCD06 extends ServiceEPBase {
	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCDDocuments</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2010-12-2上午11:29:41 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
        String fdMiningId=UserSession.getInSessionProperty("miningCode").toString();
        if(fdMiningId.equals("C.10223")){//煤质中心code D.10223
        	fdMiningId=InitialData.getInstance().getEiBlockByNo("cmes.cn.meizhiCode").getCellStr(0, "display");
        }
		EiInfo outInfo = new EiInfo();
		outInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		outInfo.set("fdCreatorId", UserSession.getUserId());//登录人的默认值
		outInfo.set("fdCreator", UserSession.getInSessionProperty("UserCname"));
		outInfo.set("fdDepartmentId", UserSession.getInSessionProperty("orgCode"));//单位的默认值		
		outInfo.set("fdDepartment", UserSession.getInSessionProperty("orgName"));//单位的默认值
		outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cp.department", "orgCode", "orgName", false,fdMiningId));
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.cd.doctype", new String[] { "地质地测", "生产设计", "通风设计", "机电设计", "质量标准化", "通知公告", "日常工作", "其它" },
				new String[] { "地质地测", "生产设计", "通风设计", "机电设计", "质量标准化", "通知公告", "日常工作", "其它" }, true));// 文档类型
		outInfo.addBlock(
				StaticBlocks.getBlockData("cmes.cd.businesstype", new String[] { "采煤", "掘进", "抽采", "机电", "运输", "通风", "安全", "其它" }, new String[] { "采煤", "掘进", "抽采", "机电", "运输", "通风", "安全", "其它" }, true));// 文档类型
		outInfo = query(inInfo);	 
		return outInfo;
	}
	
	/**
	 * 查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCDDocuments</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2010-12-2上午11:30:01 张志芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
        String fdMiningId=UserSession.getInSessionProperty("miningCode").toString();
        if(fdMiningId.equals("C.10223")){//煤质中心code D.10223
        	fdMiningId=InitialData.getInstance().getEiBlockByNo("cmes.cn.meizhiCode").getCellStr(0, "display");
        }
		ZMCDDocuments documents = new ZMCDDocuments();	
		StaticTools.setQueryParameters(inInfo, "query", "1", true);//查询文档
		StaticTools.setQueryParameters(inInfo, "fdMiningId", fdMiningId, true);
		StaticTools.setQueryParameters(inInfo, "department", UserSession.getInSessionProperty("orgCode"), true);//登录部门
		StaticTools.setQueryParameters(inInfo, "creator", UserSession.getUserId(), true);//登录人
	//	StaticTools.setQueryParameters(inInfo, "fdMiningName", UserSession.getInSessionProperty("miningName"), true);
		EiInfo outInfo = super.query(inInfo,"tZMCDDocuments.query", documents);	
		outInfo.addBlock(Department.getInstance().getMiningDepts("cmes.cp.department", "orgCode", "orgName", false,fdMiningId));	
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.cd.doctype", new String[] { "地质地测", "生产设计", "通风设计", "机电设计", "质量标准化", "通知公告", "日常工作", "其它" },
				new String[] { "地质地测", "生产设计", "通风设计", "机电设计", "质量标准化", "通知公告", "日常工作", "其它" }, true));// 文档类型
		outInfo.addBlock(
				StaticBlocks.getBlockData("cmes.cd.businesstype", new String[] { "采煤", "掘进", "抽采", "机电", "运输", "通风", "安全", "其它" }, new String[] { "采煤", "掘进", "抽采", "机电", "运输", "通风", "安全", "其它" }, true));// 文档类型
		return outInfo;
	}
	

	/**
	 * 弹出下载文件页面的查询
	 * <p>Function: queryFiles</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-23下午08:05:30 张志芳
	 * </p>
	 *
	 */
	public EiInfo queryFiles(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String keyId = (String) queryInfo.get("fdForeignId");
		inInfo.addBlock("filesresult").addBlockMeta(new ZMCDFiles().eiMetadata);
		inInfo.addBlock("filesresult").addRows(Documents.getFiles("fdForeignId", keyId));
		return inInfo;
	}
	
	
	/**
	 * 工程
	 * <p>Function: getDepartment</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-15下午01:26:12 张志芳
	 * </p>
	 *
	 
	@SuppressWarnings("rawtypes")
	private EiBlock getEngineering()
	{
		EiBlock block = new EiBlock("cmes.cd.engineering");
		
		EiColumn eiColumn = new EiColumn("fdKeyId");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map> list = Engineering.getEngineerings(null);
		
		block.setRows(list);
		return block;
	}*/
}
